<extend name="Public/base" />

<block name="body">
    <script type="text/javascript" src="__PUBLIC__/js/Validform_v5.3.2.js"></script>
    <div class="main-title location">
        <h2>
        <i>当前位置：</i>
        扩展管理 - 钩子列表 - <present name="data">编辑<else />新增</present>钩子
        </h2>
    </div>
    <!-- 修改表单 -->
    <form action="{:U('updateHook')}" method="post" class="addform">
        <div class="control-group">
            <label class="item-label"><span class="must">*</span>钩子名称<span class="check-tips Validform_checktip">（需要在程序中先添加钩子，否则无效）</span></label>
            <div class="controls">
                <input type="text" value="{$data.name}" name="name" class="text input-large" datatype="s" errormsg="存在特殊字符" nullmsg="钩子名称必填！">
            </div>
        </div>
        <div class="control-group">
            <label class="item-label">钩子描述<span class="check-tips">（钩子的描述信息）</span></label>
            <div class="controls">
                <label class="textarea input-large"><textarea name="description" >{$data.description}</textarea></label>
            </div>
        </div>
        <div class="control-group">
            <label class="item-label">钩子类型<span class="check-tips">（区分钩子的主要用途）</span></label>
            <div class="controls">
                <select name="type">
                    <volist name=":C('HOOKS_TYPE')" id="vo">
                        <option value="{$key}" <eq name="data.type" value="$key"> selected</eq>>{$vo}</option>
                    </volist>
                </select>
            </div>
        </div>
        <present name="data">
            <div class="control-group">
                <label class="item-label">钩子挂载的插件排序<span class="check-tips">（拖动后保存顺序，影响同一个钩子挂载的插件执行先后顺序）</span></label>
                <div class="controls">
                    <input type="hidden" name="addons" value="{$data.addons}" readonly>
                    <empty name="data.addons">
                        暂无插件，无法排序
                    <else />
                    <ul id="sortUl" class="dragsort">
                        <volist name=":explode(',',$data['addons'])" id="addons_vo">
                            <li class="getSort"><b>&times;</b><em>{$addons_vo}</em></li>
                        </volist>
                    </ul>
                    <script type="text/javascript">
                        $(function(){
                            $("#sortUl").dragsort({
                                dragSelector:'li',
                                placeHolderTemplate: '<li class="draging-place">&nbsp;</li>',
                                dragEnd:function(){
                                    updateVal();
                                }
                            });

                            $('#sortUl li b').click(function(){
                                $(this).parent().remove();
                                updateVal();
                            });

                            // 更新排序后的隐藏域的值
                            function updateVal() {
                                var sortVal = [];
                                $('#sortUl li').each(function(){
                                    sortVal.push($('em',this).text());
                                });
                                $("input[name='addons']").val(sortVal.join(','));
                            }
                        })
                    </script>
                    </empty>
                </div>
            </div>
        </present>
        <input type="hidden" name="id" value="{$data.id}">
        <input type="hidden" name="model" value="Hooks" />
        <button type="submit" class="primary ajax-post" target-form="addform">确 定</button>
        <button onclick="javascript:history.back(-1);return false;">返 回</button>
    </form>

    <present name="data">
        <script type="text/javascript" src="__JS__/jquery.dragsort-0.5.1.min.js"></script>
    </present>
    <script type="text/javascript">
        $(function() {
            $(".addform").Validform({
                tiptype: 2
            });
        })
    </script>
</block>

<block name="foot_js">
    $(function(){
        //左侧导航子页面高亮选中
        highlight_sidebar('{:U('hooks')}');
    });
</block>
